
package com.seekting.study;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;

import com.seekting.study.GJsonTest.Person;

public class ListTest {

    List<Person> list = new CopyOnWriteArrayList<GJsonTest.Person>();

    public void add(String s) {

        synchronized (list) {
            Person person = new Person();
            person.setName(s);
            list.add(person);
            
        }

    }

    public void pring() {
        synchronized (list) {
            for (Person person : list) {
                try {
                    Thread.sleep(100);
                } catch (InterruptedException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                System.out.println(person.getName());
                remove();
            }

        }

    }

    public void remove() {
        synchronized (list) {
            list.remove(0);
        }

    }

    public static void main(String[] args) {

        ListTest listTest = new ListTest();
        for (int i = 0; i < 10; i++) {
            listTest.add("" + i);
        }
        listTest.pring();
    }
}
